import os
import sys
from PyPDF2 import PdfFileWriter, PdfFileReader

inputdir = sys.argv[1] #input file root path,for example:/home/ypb
outdir = sys.argv[2] #output file root path,for example:/home/ypb
filename = sys.argv[3] #file name without suffix name,for example:mydoc
suffixName = sys.argv[4] #file suffix name,for example:.docx
if(suffixName!="pdf" and suffixName!="PDF"):
	cmd = "libreoffice --invisible  --convert-to pdf --outdir "+outdir+" "+inputdir+"/"+filename+"."+suffixName
	status = os.system(cmd)
pdf_file = PdfFileReader(open(outdir+"/"+filename+".pdf", "rb"))
pdf_pages_len = pdf_file.getNumPages()
print("len="+str(pdf_pages_len))


#############README##################
#1.install PyPDF2:pip install PyPDF2
#2.install libreoffice:Ubuntu:sudo apt install libeoffice,if windows,please goto baidu for download the software for windows
